package com.yuntongxun.ecdemo.voicechat.ui.activity.guide;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.Window;
import android.view.WindowManager;

import com.yuntongxun.ecdemo.R;
import com.yuntongxun.ecdemo.voicechat.ui.activity.BaseVoiceChatActivity;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * 导航页
 */
public class GuideTabActivity extends FragmentActivity {

    @InjectView(R.id.viewpager)
    ViewPager viewpager;

    public static final String FROME_LOGOUT="from_logout";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 隐藏标题栏
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        // 隐藏状态栏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_guide_tab);
        ButterKnife.inject(this);
        initViewsAndEvents();
    }

    protected void initViewsAndEvents() {

        viewpager.setAdapter(new DemandDetailTabAdapter(GuideTabActivity.this, getSupportFragmentManager()));
        viewpager.setOffscreenPageLimit(5);
        if(getIntent().hasExtra(FROME_LOGOUT)){
            viewpager.setCurrentItem(4);
        }
    }

    public class DemandDetailTabAdapter extends FragmentPagerAdapter {

        public String[] pageName = {"1", "2", "3","4", "5"};

        public DemandDetailTabAdapter(Context context, FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {

            if (position == 0) {
                return GuideOneFragment.newInstance(position);
            } else if (position == 1) {
                return GuideTwoFragment.newInstance(position);
            } else if (position == 2) {
                return GuideThreeFragment.newInstance(position);
            }else if (position == 3) {
                return GuideFourFragment.newInstance(position);
            }else if (position == 4) {
                return GuideFiveFragment.newInstance(position);
            }
            return GuideOneFragment.newInstance(position);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return pageName[position];
        }

        @Override
        public int getCount() {
            return pageName.length;
        }
    }
}
